package isanfeng.tuxiaoer.pattern.creational.Esingleton;


import java.util.HashMap;
import java.util.Map;

/**
 * 线程不安全，缓存类型
 * @author 李红辉
 * @version 1.0
 * @date 2019/10/9 17:37
 */
public class ContainerSingleton {
    private static Map<String, Object> singletonMap = new HashMap<>();

    public static void putInstance(String key, Object instance) {
        if (key != null && !key.equals("") && instance != null) {
            if (!singletonMap.containsKey(key)) {
                singletonMap.put(key, instance);
            }
        }
    }

    public static Object getInstance(String key) {
        return singletonMap.get(key);
    }
}
